import { request } from './request'

// 订单管理 API
const orderAPI = {
  // 查询订单列表
  list: (params) => {
    return request('/order/list', {
      method: 'POST',
      body: params
    })
  },

  // 查询我的订单列表
  listMyOrder: (params) => {
    return request('/order/listMyOrder', {
      method: 'POST',
      body: params
    })
  },

  // 生成订单
  generateOrder: (orderData) => {
    return request('/order/v1/generateOrder', {
      method: 'POST',
      body: orderData
    })
  },

  // 更新订单
  update: (orderData) => {
    return request('/order/update', {
      method: 'POST',
      body: orderData
    })
  },

  // 批量删除订单
  removeByIds: (ids) => {
    return request('/order/removeByIds', {
      method: 'POST',
      body: ids
    })
  },

  // 根据ID删除订单
  removeById: (id) => {
    return request('/order/removeById', {
      method: 'POST',
      body: { id }
    })
  },

  // 退款
  refund: (refundData) => {
    return request('/order/refund', {
      method: 'POST',
      body: refundData
    })
  },

  // 支付
  pay: (payData) => {
    return request('/order/pay', {
      method: 'POST',
      body: payData
    })
  },

  // 获取订单信息
  info: (params) => {
    return request('/order/info', {
      method: 'POST',
      body: params
    })
  },

  // 根据订单号获取订单
  getByOrderSn: (orderSn) => {
    return request('/order/getByOrderSn', {
      method: 'POST',
      body: { orderSn }
    })
  },

  // 根据ID获取订单
  getById: (id) => {
    return request(`/order/getById/${id}`)
  },

  // 获取最近的已支付订单
  getNearestOrder: (params) => {
    return request('/order/v1/getNearestOrder', {
      method: 'POST',
      body: params
    })
  },

  // 生成二维码
  generateORCode: (params) => {
    return request('/order/generateORCode', {
      method: 'POST',
      body: params
    })
  }
}

export { orderAPI }